﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace KP_CommonLibrary.KP_CommonControls
{
    public partial class KPUCNavVoucher : UserControl
    {
        public event EventHandler KPAddButtonClick, KPEditButtonClick, KPDeleteButtonClick, KPFindButtonClick, KPPrintButtonClick,
                                    KPExportButtonClick, KPCloseButtonClick,KPChangeCodeButtonClick;

        public bool ShowChangeCodeItem
        {
            get { return biChangeCode.Visible; }
            set
            {
                biChangeCode.Visible = value;
                bar1.Invalidate();
            }
        }
        public int ExportTemplate { get; set; }
        public KPUCNavVoucher()
        {
            InitializeComponent();
            bar1.Font = KP_UIConfig.ControlFont;
            
        }

        protected void OnChangeCodeButtonClick(object sender, EventArgs e)
        {
            if (KPChangeCodeButtonClick != null)
                KPChangeCodeButtonClick(sender, e);
        }
        protected void OnCloseButtonClick(object sender, EventArgs e)
        {
            if (KPCloseButtonClick != null)
                KPCloseButtonClick(sender, e);
        }
        protected void OnPrintButtonClick(object sender, EventArgs e)
        {
            if (KPPrintButtonClick != null)
                KPPrintButtonClick(sender, e);
        }
        protected void OnExportButtonClick(object sender, EventArgs e)
        {
            if (KPExportButtonClick != null)
                KPExportButtonClick(sender, e);
        }

        protected void OnAddButtonClick(object sender, EventArgs e)
        {
            if (KPAddButtonClick != null)
                KPAddButtonClick(sender, e);
        }
        protected void OnEditButtonClick(object sender, EventArgs e)
        {
            if (KPEditButtonClick != null)
                KPEditButtonClick(sender, e);
        }
        protected void OnDeleteButtonClick(object sender, EventArgs e)
        {
            if (KPDeleteButtonClick != null)
                KPDeleteButtonClick(sender, e);
        }
        protected void OnFindButtonClick(object sender, EventArgs e)
        {
            if (KPFindButtonClick != null)
                KPFindButtonClick(sender, e);
        }

        private void biAddNew_Click(object sender, EventArgs e)
        {
            OnAddButtonClick(sender, e);
        }

        private void biEdit_Click(object sender, EventArgs e)
        {
            OnEditButtonClick(sender, e);
        }

        private void biDelete_Click(object sender, EventArgs e)
        {
            OnDeleteButtonClick(sender, e);
        }

        private void biFind_Click(object sender, EventArgs e)
        {
            OnFindButtonClick(sender, e);
        }

        private void biPrint_Click(object sender, EventArgs e)
        {
            OnPrintButtonClick(sender, e);
        }

        private void biExport_Click(object sender, EventArgs e)
        {
            OnExportButtonClick(sender, e);
        }

        private void biClose_Click(object sender, EventArgs e)
        {
            OnCloseButtonClick(sender, e);
        }
        public virtual bool DispatchCmdKey(ref Message msg, Keys keyData)
        {
            
            if (keyData == Keys.F3)
            {
                //F3 Edit
                OnEditButtonClick(this, new EventArgs());
                return true;
            }
            else if (keyData == Keys.F4)
            {
                //Thêm
                OnAddButtonClick(this, new EventArgs());
                return true;
            }
            else if (keyData == Keys.F8)
            {
                //Xóa
                OnDeleteButtonClick(this, new EventArgs());
                return true;
            }
            else if (keyData == Keys.F5)
            {
                //Tìm kiếm
                OnFindButtonClick(this, new EventArgs());
                return true;
            }
            else if (keyData == Keys.F7)
            {
                //In
                OnPrintButtonClick(this, new EventArgs());
                return true;
            }
            else if (keyData == Keys.F9)
            {
                //Export
                OnExportButtonClick(this, new EventArgs());
                return true;
            }
            else if (keyData == Keys.Escape)
            {
                OnCloseButtonClick(this, new EventArgs());
                return true;
            }
            return false;
        }
    }
}
